package com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.utils.*;
import com.css.zfzx.sjcj.common.utils.*;
import com.css.zfzx.sjcj.modules.boundary.repository.BoundaryNativeRepository;
import com.css.zfzx.sjcj.modules.boundary.repository.entity.BoundaryEntity;
import com.css.zfzx.sjcj.modules.boundary.viewobjects.BoundaryQueryParams;
import com.css.zfzx.sjcj.modules.pchjdzb.service.PcHjDzbService;
import com.css.zfzx.sjcj.modules.qhmapfiles.repository.QhMapFilesImport;
import com.css.zfzx.sjcj.modules.qhmapfiles.repository.entity.QhMapFilesEntity;
import com.css.zfzx.sjcj.modules.qhmapfiles.viewobjects.QhMapFilesQueryParams;
import com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.repository.QhRiskLevelMapPointProvinceImport;
import com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.repository.QhRiskLevelMapPointProvinceNativeRepository;
import com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.repository.QhRiskLevelMapPointProvinceRepository;
import com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.repository.entity.QhRiskLevelMapPointProvinceEntity;
import com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.service.QhRiskLevelMapPointProvinceService;
import com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.viewobjects.QhRiskLevelMapPointQueryParams;
import com.css.zfzx.sjcj.modules.qhrisklevelmappointprovince.viewobjects.QhRiskLevelMapPointVo;
import lombok.extern.slf4j.Slf4j;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.opengis.feature.simple.SimpleFeature;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.*;

/**
 * @author andy
 * @date 2021-01-26
 */
@Service
@Slf4j
public class QhRiskLevelMapPointProvinceServiceImpl implements QhRiskLevelMapPointProvinceService {

	@Autowired
    private QhRiskLevelMapPointProvinceRepository qhRiskLevelMapRepository;
    @Autowired
    private QhRiskLevelMapPointProvinceNativeRepository qhRiskLevelMapPointNativeRepository;
    @Autowired
    private QhRiskLevelMapPointProvinceImport qhRiskLevelMapInitial;
    @Autowired
    private QhMapFilesImport qhMapFilesImport;//上传文件管理
    @Autowired
    private PcHjDzbService pcHjDzbService;

    @Override
    public JSONObject queryQhRiskLevelMaps(QhRiskLevelMapPointQueryParams queryParams, int curPage, int pageSize) {
        Page<QhRiskLevelMapPointProvinceEntity> qhRiskLevelMapPage = this.qhRiskLevelMapPointNativeRepository.queryQhRiskLevelMaps(queryParams, curPage, pageSize);
        JSONObject jsonObject = PlatformPageUtils.formatPageData(qhRiskLevelMapPage);
        return jsonObject;
    }

    @Override
    public JSONObject queryQhRiskLevelMapsByFileName(QhRiskLevelMapPointQueryParams queryParams, int curPage, int pageSize, String sort, String order) {
        if (!PlatformObjectUtils.isEmpty(sort) && sort.length() > 0) {
            sort = CheckObjFields.propertyChange(sort);
        }
        Page<QhRiskLevelMapPointProvinceEntity> qhRiskLevelMapPage = this.qhRiskLevelMapPointNativeRepository.queryRiskLevelMapsByFileNameJDBC(queryParams, curPage, pageSize, sort, order);
        JSONObject jsonObject = PlatformPageUtils.formatPageData(qhRiskLevelMapPage);
        return jsonObject;
    }

    @Override
    public QhRiskLevelMapPointProvinceEntity getQhRiskLevelMap(String id) {
        QhRiskLevelMapPointProvinceEntity qhRiskLevelMap = this.qhRiskLevelMapRepository.findById(id).orElse(null);
         return qhRiskLevelMap;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public QhRiskLevelMapPointProvinceEntity saveQhRiskLevelMap(QhRiskLevelMapPointProvinceEntity qhRiskLevelMap) {
        String uuid = UUIDGenerator.getUUID();
        qhRiskLevelMap.setUuid(uuid);
        qhRiskLevelMap.setCreateUser(PlatformSessionUtils.getUserId());
        qhRiskLevelMap.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        this.qhRiskLevelMapRepository.save(qhRiskLevelMap);
        return qhRiskLevelMap;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public QhRiskLevelMapPointProvinceEntity updateQhRiskLevelMap(QhRiskLevelMapPointProvinceEntity qhRiskLevelMap) {
        qhRiskLevelMap.setUpdateUser(PlatformSessionUtils.getUserId());
        qhRiskLevelMap.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        String id = qhRiskLevelMap.getUuid();
        QhRiskLevelMapPointProvinceEntity one = qhRiskLevelMapRepository.findById(id).get();
        BeanUtil.copyPropertiesIgnoreNull(qhRiskLevelMap, one);
        this.qhRiskLevelMapRepository.save(qhRiskLevelMap);
        return qhRiskLevelMap;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteQhRiskLevelMaps(List<String> ids) {
        List<QhRiskLevelMapPointProvinceEntity> qhRiskLevelMapList = this.qhRiskLevelMapRepository.findAllById(ids);
        if(!PlatformObjectUtils.isEmpty(qhRiskLevelMapList) && qhRiskLevelMapList.size() > 0) {
            for(QhRiskLevelMapPointProvinceEntity qhRiskLevelMap : qhRiskLevelMapList) {
                this.qhRiskLevelMapRepository.delete(qhRiskLevelMap);
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteQhRiskLevelMapsByFileName(List<String> fileNames) {
        for (int i = 0; i < fileNames.size(); i++) {
            //根据文件名获取省名
            String fileName = fileNames.get(i);
            String province = "";
            if(fileName.contains("RLM__")){
                province = fileName.split("RLM__")[1].split("_")[0];
            }
            QhRiskLevelMapPointQueryParams queryParams = new QhRiskLevelMapPointQueryParams();
            queryParams.setProvince(province);
            queryParams.setAffiliatedFileName(fileNames.get(i));
            System.out.println(new Date()+"----开始删除." + fileNames.get(i));
            List<String> uuidList = this.qhRiskLevelMapPointNativeRepository.listQhRiskLevelMapPointsUuidsByJDBC(queryParams);
            if(!PlatformObjectUtils.isEmpty(uuidList) && uuidList.size() > 0) {
                System.out.println(new Date()+"----开始逻辑删除." + uuidList.size() + "条数据");
                //物理删
                //qhRiskLevelMapInitial.sqlBatchDeleteEntities(qhRiskLevelMapList);
                //逻辑删
                qhRiskLevelMapInitial.newSqlBatchLogicDeleteEntities(province,uuidList);
                System.out.println(new Date()+"----结束逻辑删除." + uuidList.size() + "条数据");
            }
            //查询上传文件表
            QhMapFilesQueryParams qhMapFilesQueryParams = new QhMapFilesQueryParams();
            qhMapFilesQueryParams.setAffiliatedFileName(fileNames.get(i));
            qhMapFilesQueryParams.setType("RLM_");//上传类型（PED_,RLM_,RLMPolygon_,SCR_）
            qhMapFilesQueryParams.setIsDelete("0");//未删除
            List<QhMapFilesEntity> list = qhMapFilesImport.searchMapFiles(qhMapFilesQueryParams);
            if(!PlatformObjectUtils.isEmpty(list) && list.size() > 0) {
                //逻辑删--上传文件表
                qhMapFilesImport.sqlBatchLogicDeleteEntities(list);
            }
            System.out.println(new Date()+"----结束删除." + fileNames.get(i));
        }
    }

    @Override
    public JSONObject getQhRiskLevelMaps(QhRiskLevelMapPointQueryParams queryParams) {
        List<QhRiskLevelMapPointProvinceEntity> qhRiskLevelMaps = this.qhRiskLevelMapPointNativeRepository.listQhRiskLevelMaps(queryParams);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", qhRiskLevelMaps);
        return jsonObject;
    }

    @Override
    public JSONObject searchQhRiskLevelMaps(QhRiskLevelMapPointQueryParams queryParams) {
        List<QhRiskLevelMapPointProvinceEntity> qhRiskLevelMaps = this.qhRiskLevelMapPointNativeRepository.searchRiskLevelMapsByJDBC(queryParams);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("zoom", queryParams.getZoom());
        jsonObject.put("data", qhRiskLevelMaps);
        return jsonObject;
    }

    @Override
    public void saveOrUpdate(QhRiskLevelMapPointProvinceEntity scrEntity) {
        QhRiskLevelMapPointQueryParams queryParams = new QhRiskLevelMapPointQueryParams();
        queryParams.setProvince(scrEntity.getProvince());
        queryParams.setCity(scrEntity.getCity());
        queryParams.setArea(scrEntity.getArea());
        List<QhRiskLevelMapPointProvinceEntity> scrEntities = qhRiskLevelMapPointNativeRepository.listQhRiskLevelMaps(queryParams);
        // 若查到数据为空，则新增
        if (CollectionUtils.isEmpty(scrEntities)) {
            this.saveQhRiskLevelMap(scrEntity);
        } else {
            if (scrEntities.size() == 1) {
                QhRiskLevelMapPointProvinceEntity sourceProvinceEntity = scrEntities.get(0);
                BeanUtil.copyPropertiesIgnoreNull(scrEntity, sourceProvinceEntity);
                this.updateQhRiskLevelMap(sourceProvinceEntity);
            } else {
                throw new RuntimeException("库中该数据最多一条，请管理员清理数据库冗余数据！");
            }
        }
    }

    @Override
    public String judgeFileParams(String[] datas) {
        String str = "";
        Set<String> set = new HashSet<String>(Arrays.asList(datas));
        if(!set.contains("A")){
            str += "A,";
        }
        if(!set.contains("B")){
            str += "B,";
        }
        if(!set.contains("C")){
            str += "C,";
        }
        return str;
    }

    private String judgeFieldParams(List<List<Object>> list) {
        String str = "";
        for (int i = 0; i < list.size(); i++) {
            List<Object> values = list.get(i);
            for (int j = 0; j < values.size(); j++) {
                if ("".equals(values.get(j))) {
                    str += "第 " + i + " 条数据第 " + j + " 个字段数据为空.<br/>";
                }
            }
        }
        return str;
    }

    @Override
    public int lookUpQhRiskLevelMaps(QhRiskLevelMapPointQueryParams queryParams,boolean isNewTable) {
        int count = this.qhRiskLevelMapPointNativeRepository.lookUpQhRiskLevelMaps(queryParams,isNewTable);
        return count;
    }

    private boolean geometryIsEqualsCoordinate(String wkt, String lon, String lat) {
        //POINT (119.302 35.23300000088943)
        String wktPart = "";
        if (wkt.toLowerCase().indexOf("multipoint") != -1) {
            wktPart = wkt.substring(wkt.indexOf("(") + 2, wkt.lastIndexOf(")") - 1);
        } else if (wkt.toLowerCase().indexOf("point") != -1) {
            wktPart = wkt.substring(wkt.indexOf("(") + 1, wkt.lastIndexOf(")"));
        }

        int det = 1 + 6;
        String[] array = wktPart.split(" ");
        String longitude = array[0], latitude = array[1];
        String newWktLongitudeStr = keepDecimalDigits(longitude, det), newWktLatitudeStr = keepDecimalDigits(latitude, det);
        String newLongitudeStr = keepDecimalDigits(lon, det), newLatitudeStr = keepDecimalDigits(lat, det);

        double newWktLongitude = Double.parseDouble(newWktLongitudeStr), newWktLatitude = Double.parseDouble(newWktLatitudeStr);
        double newLongitude = Double.parseDouble(newLongitudeStr), newLatitude = Double.parseDouble(newLatitudeStr);

        if (newWktLongitude == newLongitude && newWktLatitude == newLatitude) return true;
        return false;
    }
    /*private String keepDecimalDigits(String floatStr, int det) {
        int index = floatStr.indexOf("."), len = floatStr.length();
        if (index == -1) return floatStr;
        String floatPart = floatStr.substring(index + 1, (len > (index + det)) ? (index + det) : len);
        String newFloatStr = floatStr.substring(0, index) + "." + floatPart;
        return newFloatStr;
    }*/
    private String keepDecimalDigits(String floatStr, int det) {
        int index = floatStr.indexOf("."), len = floatStr.length();
        if (index == -1) return floatStr;
        int temp=det+3;
        String tempfloatPart=floatStr.substring(index + 1, (len > (index + temp)) ? (index + temp) : len);
        String floatPart = floatStr.substring(index + 1, (len > (index + det)) ? (index + det) : len);
        if(tempfloatPart.length()>floatPart.length()&&tempfloatPart.startsWith(floatPart)&&floatPart.endsWith("9")){
            int findex=0;
            String sindex="";
            for(int i=floatPart.length()-1;i>0;i--){
                String subStr = floatPart.substring(i, i+1);
                if(subStr.equals("9")){
                    continue;
                }
                findex=i;
                sindex=Integer.toString(Integer.parseInt(subStr)+1);
                break;
            }
            floatPart= floatPart.substring(0, findex)+ sindex;
        }
        String newFloatStr = floatStr.substring(0, index) + "." + floatPart;
        return newFloatStr;
    }

    //保存到上传文件管理表
    private void saveMapFiles(QhMapFilesEntity qhMapFilesEntity) throws Exception {
        List<QhMapFilesEntity> list = new ArrayList<QhMapFilesEntity>();
        list.add(qhMapFilesEntity);
        String affiliatedFileName = qhMapFilesEntity.getAffiliatedFileName();
        String province = qhMapFilesEntity.getProvince();
        String city = qhMapFilesEntity.getCity();
        String area = qhMapFilesEntity.getArea();
        //逻辑删除未保存的文件
        deleteMapFileByParams(affiliatedFileName, province, city, area);
        //保存
        qhMapFilesImport.sqlBatchSaveEntities(list);
    }

    //逻辑删除未保存的文件
    private void deleteMapFileByParams(String affiliatedFileName, String province, String city, String area) {
        //查询上传文件表
        QhMapFilesQueryParams qhMapFilesQueryParams = new QhMapFilesQueryParams();
        qhMapFilesQueryParams.setProvince(province);
        qhMapFilesQueryParams.setCity(city);
        qhMapFilesQueryParams.setArea(area);
        //qhMapFilesQueryParams.setAffiliatedFileName(affiliatedFileName);
        qhMapFilesQueryParams.setType("RLM_");//上传类型（PED_,RLM_,RLMPolygon_,SCR_）
        //查询文件（未删除）
        List<QhMapFilesEntity> list = qhMapFilesImport.searchMapFilesUnSaved(qhMapFilesQueryParams);
        if(!PlatformObjectUtils.isEmpty(list) && list.size() > 0) {
            //逻辑删--上传文件表
            qhMapFilesImport.sqlBatchLogicDeleteEntities(list);
        }
    }

    //校验shp文件
    public String checkSHPFiles(String filePath, String province, String city, String area) {
        System.out.println(new Date()+"-------------------1.开始readSHPFile");
        System.out.println(new Date()+"-------------------2.开始校验");
        //获取省市县所在区域字符串
        String boundariesCoordinate = getDistrictBoundaryCoordinate(province, city, area);
        //读取shp文件并校验--type上传类型（PED_,RLM_,RLMPolygon_,SCR_）
        List<Object> list = VectorDataUtil.readSHPFileCheck(filePath, "UTF-8","RLM_", boundariesCoordinate);
        String codeType = (String) list.get(0);//编码类型（0：UTF-8，1：GBK）
        int dataLength = (int) list.get(1);//数据长度
        String checkResult = (String) list.get(2);//校验结果
        //编码类型（0：UTF-8，1：GBK）
        if (codeType.equals("UTF-8")) {
            codeType = "0";
        }else{
            codeType = "1";
        }
        if(checkResult.equals("校验成功")){
            System.out.println(new Date()+"-------------------1.完成校验GeometryIsNotEqualsCoordinate");
            System.out.println(new Date()+"-------------------2.完成校验是否有乱码");
            System.out.println(new Date()+"-------------------3.完成校验字段空值");
            System.out.println(new Date()+"-------------------4.完成校验是否为罗马数字");
            System.out.println(new Date()+"-----------校验成功.");
        }else{
            System.out.println(new Date()+"-----------校验失败."+checkResult);
            return checkResult;
        }
        System.out.println(new Date()+"-----------3.结束校验");

        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length() - 4);
        // 返回的消息
        StringBuilder returnMsg = new StringBuilder();
        //上传文件信息
        QhMapFilesEntity qhMapFilesEntity = new QhMapFilesEntity();
        qhMapFilesEntity.setFilepath(filePath);
        qhMapFilesEntity.setProvince(province);
        qhMapFilesEntity.setCity(city);
        qhMapFilesEntity.setArea(area);
        qhMapFilesEntity.setAffiliatedFileName(fileName);
        qhMapFilesEntity.setIsSave("0");
        qhMapFilesEntity.setIsDelete("0");
        qhMapFilesEntity.setType("RLM_");//类型
        qhMapFilesEntity.setPostfix("shp");
        qhMapFilesEntity.setQualityStatus("0");//上传省市级类型（0：省，1：市）
        qhMapFilesEntity.setCodeType(codeType);//编码类型（0：UTF-8，1：GBK）
        qhMapFilesEntity.setDataLength(dataLength);//数据长度
        try {
            System.out.println(new Date()+"-------------------4.开始保存");
            //保存到上传文件管理表
            this.saveMapFiles(qhMapFilesEntity);
            System.out.println(new Date()+"-------------------5.结束保存");
            returnMsg.append("等待导入" + dataLength + "条数据.请第二天查询上传内容.");
            return returnMsg.toString();
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
            return "插入或更新数据出现错误: <br/>" + e.getMessage();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "数据导入失败, 服务器内部出现异常!";
        }
    }

    //保存--zyt
    @Override
    public String newImportShapeFile(String filePath, String province, String city, String area, String createUser,String codeType,int dataLength) {
        // 返回的消息
        StringBuilder returnMsg = new StringBuilder();
        try {
            System.out.println(new Date()+"-------------------1.开始保存");
            //保存--zyt
            int count = this.newSaveData(filePath,province,city,area, codeType, dataLength,createUser);
            if(count==dataLength){
                //保存一条记录：dataType(1:PGA,2等级图矢量点)
                pcHjDzbService.jdbcSave(province, city, area,"2");
                System.out.println(new Date()+"-------------------2.结束保存");
                returnMsg.append("成功导入" + count + "条数据.");
            }else{
                System.out.println(new Date()+"-------------------2.结束保存");
                returnMsg.append("导入出现异常，仅导入" + count + "条数据.");
            }
            return returnMsg.toString();
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
            return "插入或更新数据出现错误: <br/>" + e.getMessage();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "数据导入失败, 服务器内部出现异常!";
        }
    }

    //保存--zyt
    private int newSaveData(String filePath, String province, String city, String area, String codeType, int dataLength, String createUser) {
        int count = qhRiskLevelMapInitial.newSqlBatchSaveEntities(filePath,province,city,area,codeType,dataLength,createUser);

        return count;
    }

    @Autowired
    private BoundaryNativeRepository boundaryNativeRepository;
    //获取省市县所在区域字符串
    public String getDistrictBoundaryCoordinate(String province, String city, String area){
        String coordinate = "";
        BoundaryQueryParams queryParams = new BoundaryQueryParams();
        queryParams.setType("1");//1: 行政区划 2: 普查区划
        queryParams.setLevel("0");//0: 省 1: 市 2: 县
        queryParams.setName(province);//省
        queryParams.setProvince(province);
        queryParams.setCity(city);
        queryParams.setArea(area);
        //查询省市县所在区域边界列表
        List<BoundaryEntity> boundaryEntities = this.boundaryNativeRepository.newListBoundaries(queryParams);
        if (boundaryEntities.size() == 1) {
            BoundaryEntity boundaryEntity = boundaryEntities.get(0);
            coordinate = boundaryEntity.getCoordinate();

        } else if (boundaryEntities.size() == 0) {
            System.out.println("NoDistrictBoundaryData");
        } else {
            System.out.println("DistrictBoundaryDataRedundance");
        }
        return coordinate;
    }

    //校验GDB文件
    public String checkGDBFiles(String filePath, String province, String city, String area) {
        System.out.println(new Date()+"-------------------1.开始readGDBFile");
        System.out.println(new Date()+"-------------------2.开始校验");
        //获取省市县所在区域字符串
        String boundariesCoordinate = getDistrictBoundaryCoordinate(province, city, area);
        //读取GDB文件并校验--type上传类型（PED_,RLM_,RLMPolygon_,SCR_）
        List<Object> list = GdbDataUtil.readGDBFileCheck(filePath, "UTF-8","RLM_", boundariesCoordinate);
        String codeType = (String) list.get(0);//编码类型（0：UTF-8，1：GBK）
        int dataLength = (int) list.get(1);//数据长度
        String checkResult = (String) list.get(2);//校验结果
        //编码类型（0：UTF-8，1：GBK）
        if (codeType.equals("UTF-8")) {
            codeType = "0";
        }else{
            codeType = "1";
        }
        if(checkResult.equals("校验成功")){
            System.out.println(new Date()+"-------------------1.完成校验GeometryIsNotEqualsCoordinate");
            System.out.println(new Date()+"-------------------2.完成校验是否有乱码");
            System.out.println(new Date()+"-------------------3.完成校验字段空值");
            System.out.println(new Date()+"-------------------4.完成校验是否为罗马数字");
            System.out.println(new Date()+"-----------校验成功.");
        }else{
            System.out.println(new Date()+"-----------校验失败."+checkResult);
            return checkResult;
        }
        System.out.println(new Date()+"-----------3.结束校验");

        //String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length() - 4);
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length());
        // 返回的消息
        StringBuilder returnMsg = new StringBuilder();
        //上传文件信息
        QhMapFilesEntity qhMapFilesEntity = new QhMapFilesEntity();
        qhMapFilesEntity.setFilepath(filePath);
        qhMapFilesEntity.setProvince(province);
        qhMapFilesEntity.setCity(city);
        qhMapFilesEntity.setArea(area);
        qhMapFilesEntity.setAffiliatedFileName(fileName);
        qhMapFilesEntity.setIsSave("0");
        qhMapFilesEntity.setIsDelete("0");
        qhMapFilesEntity.setType("RLM_");//类型
        qhMapFilesEntity.setPostfix("gdb");
        qhMapFilesEntity.setQualityStatus("0");//上传省市级类型（0：省，1：市）
        qhMapFilesEntity.setCodeType(codeType);//编码类型（0：UTF-8，1：GBK）
        qhMapFilesEntity.setDataLength(dataLength);//数据长度
        try {
            System.out.println(new Date()+"-------------------4.开始保存");
            //保存到上传文件管理表
            this.saveMapFiles(qhMapFilesEntity);
            System.out.println(new Date()+"-------------------5.结束保存");
            returnMsg.append("等待导入" + dataLength + "条数据.请第二天查询上传内容.");
            return returnMsg.toString();
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
            return "插入或更新数据出现错误: <br/>" + e.getMessage();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "数据导入失败, 服务器内部出现异常!";
        }
    }

    //保存GDB文件
    @Override
    public String newImportGDBFile(String filePath, String province, String city, String area, String createUser,String codeType,int dataLength) {
        // 返回的消息
        StringBuilder returnMsg = new StringBuilder();
        try {
            System.out.println(new Date()+"-------------------1.开始保存");
            //保存--zyt
            int count = qhRiskLevelMapInitial.newSqlBatchSaveEntities_GDB(filePath,province,city,area,codeType,dataLength,createUser);
            if(count==dataLength){
                //保存一条记录：dataType(1:PGA,2等级图矢量点)
                pcHjDzbService.jdbcSave(province, city, area,"2");
                System.out.println(new Date()+"-------------------2.结束保存");
                returnMsg.append("成功导入" + count + "条数据.");
            }else{
                System.out.println(new Date()+"-------------------2.结束保存");
                returnMsg.append("导入出现异常，仅导入" + count + "条数据.");
            }
            return returnMsg.toString();
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
            return "插入或更新数据出现错误: <br/>" + e.getMessage();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "数据导入失败, 服务器内部出现异常!";
        }
    }
}
